package com.artisan.domain.repositoryInterface;

import com.artisan.domain.entity.MRole;
import com.artisan.domain.info.RoleInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * 角色数据访问接口
 */
@Repository
public interface IRoleRepository extends JpaRepository<MRole, Integer> {
    @Query(value = "select c from MRole c left join MRoleGroup rg on c.roleGroupId=rg.id where c.status=1 order by c.addDate desc ")
    Page<RoleInfo> findList(Pageable pageable);

    @Query(value = "select c from MRole c left join MRoleGroup rg on c.roleGroupId=rg.id where c.status=1 and c.id=:id order by c.id desc ")
    RoleInfo find(@Param("id") int id);
}
